package com.szyjjk.service;

import com.szyjjk.entity.RunProperty;
import com.szyjjk.entity.RunPropertyExample;
import com.szyjjk.mapper.RunPropertyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: szyjjk
 * @description: 属性服务
 * @author: yangyue
 * @create: 2020-10-10 16:14
 */
@Service
public class RunPropertyServices {
    @Autowired
    private RunPropertyMapper runPropertyMapper;

    /**
     * @return java.util.List<com.szyjjk.entity.RunProperty>
     * @Author yangyue
     * @Description //TODO 查询全部属性
     * @Date 10:29 2020/6/8
     * @Param []
     **/
    public List<RunProperty> findProAll() {
        return runPropertyMapper.selectByExample(null);
    }
    /**
     * @Author yangyue
     * @Description //TODO 修改属性
     * @Date 15:22 2020/10/28
     * @Param [runHisData]
     * @return java.lang.Boolean
     **/
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public Boolean editRunProperty(RunProperty runHisData) {
        try {
            //todo 可填加后续逻辑
            runPropertyMapper.updateByPrimaryKeySelective(runHisData);
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    /**
     * @Author yangyue
     * @Description //TODO 查询全部属性数量
     * @Date 11:05 2020/10/27
     * @Param []
     * @return java.util.List<com.szyjjk.entity.RunProperty>
     **/
    public int findProAllCount() {
        return runPropertyMapper.countByExample(null);
    }
    
    
    /**
     * @Author yangyue
     * @Description //TODO 根据分页查询属性表
     * @Date 11:03 2020/10/27
     * @Param [pageNo, pageSize]
     * @return java.util.List<com.szyjjk.entity.RunProperty>
     **/
    public List<RunProperty> findPageCount(Integer pageNo, Integer pageSize){
        RunPropertyExample example=new RunPropertyExample();
        example.setOrderByClause("pro_fileType asc limit "+pageNo+" , "+pageSize);
        return runPropertyMapper.selectByExample(example);
    }


    /**
     * @return com.szyjjk.entity.RunProperty
     * @Author yangyue
     * @Description //TODO 查询ID   属性表
     * @Date 11:07 2020/6/8
     * @Param [id]
     **/
    public RunProperty findByIDPro(String id) {
        return runPropertyMapper.selectByPrimaryKey(id);
    }


    /**
     * @return java.util.List<com.szyjjk.entity.RunProperty>
     * @Author yangyue
     * @Description //TODO 根据文件类别查询属性  1 是硬件  0 为模拟
     * @Date 16:20 2020/10/10
     * @Param [fileType]
     **/
    public List<RunProperty> findByFileType(int fileType) {
        RunPropertyExample example = new RunPropertyExample();
        example.createCriteria().andProFiletypeEqualTo(fileType);
        return runPropertyMapper.selectByExample(example);
    }

    /**
     * @Author yangyue
     * @Description //TODO 查询英文名字
     * @Date 14:23 2020/11/2
     * @Param [proName]
     * @return com.szyjjk.entity.RunProperty
     **/
    public RunProperty findByProName(String proName) {
        RunPropertyExample example = new RunPropertyExample();
        example.createCriteria().andProNameenEqualTo(proName);
        List<RunProperty> runPropertyList=runPropertyMapper.selectByExample(example);
        if(runPropertyList.size()>0){
            return runPropertyList.get(0);
        }
        return null;
    }
    public RunProperty findByProName1(String proName) {
    	RunPropertyExample example = new RunPropertyExample();
    	example.createCriteria().andProNamechEqualTo(proName);
    	List<RunProperty> runPropertyList=runPropertyMapper.selectByExample(example);
    	if(runPropertyList.size()>0){
    		return runPropertyList.get(0);
    	}
    	return null;
    }






}